From 4b3b0d5ce569e2159bb421b2395ff35f9b875559 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Fri, 19 Jan 2007 18:32:28 +0000 Subject: [PATCH] [LIBXC] Refactor xc_domain_resume() into its own source file. The idea is that this file is where we will have two implementations of 'suspend cancellation': one which the guest is aware of (and is faster) and the other which does more work to avoid requiring guest modifications. Signed-off-by: Keir Fraser --- tools/libxc/Makefile | 1 + tools/libxc/xc_domain.c | 17 +++-------------- tools/libxc/xc_resume.c | 35 +++++++++++++++++++++++++++++++++++ tools/libxc/xenctrl.h | 6 +++--- 4 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 tools/libxc/xc_resume.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 8a563d00e0..03dae2992e 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -15,6 +15,7 @@ CTRL_SRCS-y += xc_private.c CTRL_SRCS-y += xc_sedf.c CTRL_SRCS-y += xc_csched.c CTRL_SRCS-y += xc_tbuf.c +CTRL_SRCS-y += xc_resume.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 995b877ac0..4b9c5ea70d 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -89,16 +89,6 @@ int xc_domain_shutdown(int xc_handle, } -int xc_domain_resume(int xc_handle, - uint32_t domid) -{ - DECLARE_DOMCTL; - domctl.cmd = XEN_DOMCTL_resumedomain; - domctl.domain = (domid_t)domid; - return do_domctl(xc_handle, &domctl); -} - - int xc_vcpu_setaffinity(int xc_handle, uint32_t domid, int vcpu, @@ -293,9 +283,9 @@ int xc_domain_hvm_setcontext(int xc_handle, } int xc_vcpu_getcontext(int xc_handle, - uint32_t domid, - uint32_t vcpu, - vcpu_guest_context_t *ctxt) + uint32_t domid, + uint32_t vcpu, + vcpu_guest_context_t *ctxt) { int rc; DECLARE_DOMCTL; @@ -611,7 +601,6 @@ int xc_vcpu_setcontext(int xc_handle, unlock_pages(ctxt, sizeof(*ctxt)); return rc; - } int xc_domain_irq_permission(int xc_handle, diff --git a/tools/libxc/xc_resume.c b/tools/libxc/xc_resume.c new file mode 100644 index 0000000000..ea9e121054 --- /dev/null +++ b/tools/libxc/xc_resume.c @@ -0,0 +1,35 @@ +#include "xc_private.h" + +/* + * Resume execution of a domain after suspend shutdown. + * This can happen in one of two ways: + * 1. Resume with special return code. + * 2. Reset guest environment so it believes it is resumed in a new + * domain context. + * (2) should be used only for guests which cannot handle the special + * new return code. (1) is always safe (but slower). + * + * XXX Only (2) is implemented below. We need to use (1) by default! + */ +int xc_domain_resume(int xc_handle, uint32_t domid) +{ + vcpu_guest_context_t ctxt; + DECLARE_DOMCTL; + int rc; + + /* + * Set hypercall return code to indicate that suspend is cancelled + * (rather than resuming in a new domain context). + */ +#if defined(__i386__) || defined(__x86_64__) + if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt)) != 0 ) + return rc; + ctxt.user_regs.eax = 1; + if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt)) != 0 ) + return rc; +#endif + + domctl.cmd = XEN_DOMCTL_resumedomain; + domctl.domain = domid; + return do_domctl(xc_handle, &domctl); +} diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 37d12d5788..9c175e187c 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -360,9 +360,9 @@ int xc_domain_hvm_setcontext(int xc_handle, * @return 0 on success, -1 on failure */ int xc_vcpu_getcontext(int xc_handle, - uint32_t domid, - uint32_t vcpu, - vcpu_guest_context_t *ctxt); + uint32_t domid, + uint32_t vcpu, + vcpu_guest_context_t *ctxt); typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t; int xc_vcpu_getinfo(int xc_handle, -- 2.30.2